import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Cache } from "../../../cache/Cache";
import { DomWarConst } from "../DomWarConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { SDominionInvite } from "../../../../../Message/Public/SDominionInvite";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class UnionInviteInfoCellRender
    
    export  class UnionInviteInfoCellRender extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            var loc1=3;
            this._servName = ObjCreate.createGTextField("", 0, loc1, 200, 20, this, GlobalStyle.textFormat6);
            var loc2=GlobalStyle.textFormat6.clone();
            loc2.align = "center";
            this._desTxt = ObjCreate.createGTextField("", 220, loc1, 430, 20, this, loc2);
            this._agreeBtn = ObjCreate.createGButton(Language.getString(90664), 670, 2, 40, 25, this);
            this._agreeBtn.drawNow();
            this._agreeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this._refuseBtn = ObjCreate.createGButton(Language.getString(90663), 735, 0, 40, 25, this);
            this._refuseBtn.drawNow();
            this._refuseBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            ObjCreate.createBg(0, 27, 780, 2, this, ImagesConst.SplitLine);
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this.info) 
            {
                if (Cache.instance.country.isDominionPrivilege()) 
                {
                    loc1 = {"x": this.info.x, "y": this.info.y};
                    var loc2=arg1.currentTarget;
                    switch (loc2) 
                    {
                        case this._agreeBtn:
                        {
                            loc1.reply = 1;
                            break;
                        }
                        case this._refuseBtn:
                        {
                            loc1.reply = 0;
                            break;
                        }
                    }
                    if (DomWarConst.isInviteAtk(this.info.force)) 
                    {
                        loc1.proxyId = this.info.mainActId.proxyId;
                        loc1.serverId = this.info.mainActId.serverId;
                    }
                    else 
                    {
                        loc1.proxyId = this.info.mainDefId.proxyId;
                        loc1.serverId = this.info.mainDefId.serverId;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.UnionInviteReply, loc1));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(90659));
                }
            }
            return;
        }

        /* internal  */get info(): SDominionInvite
        {
            return this._data as SDominionInvite;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            if (arg1 == null) 
            {
                return;
            }
            super.data = arg1;
            if (this.info) 
            {
                loc1 = "";
                if (DomWarConst.isInviteAtk(this.info.force)) 
                {
                    this._servName.text = DomWarConst.getSerNameByDomId(this.info.mainActId);
                    loc1 = DomWarConst.getSerNameByDomId(this.info.mainDefId);
                }
                else 
                {
                    this._servName.text = DomWarConst.getSerNameByDomId(this.info.mainDefId);
                    loc1 = DomWarConst.getSerNameByDomId(this.info.mainActId);
                }
                loc1 = loc1 + this.info.name;
                this._desTxt.text = Language.getStringByParam(90660, loc1, DomWarConst.getInviteTypeName(this.info.force));
            }
            return;
        }

        /* internal */ /* var */_servName: GTextFiled;

        /* internal */ /* var */_desTxt: GTextFiled;

        /* internal */ /* var */_agreeBtn: GButton;

        /* internal */ /* var */_refuseBtn: GButton;
    }
